#!/bin/sh
killall -9 monitor.sh
killall -9 usb.sh
killall -9 bondCheck.sh
killall -9 air_flash
killall -9 rsync
killall -9 vsftpd
killall -9 tcpsvd

#卸载分区
function parts_umount()
{
    fdisk -l |  grep -v Disk | grep -v Device| grep -v Units| grep -v Sector| grep -v size| grep -v size|grep sda|awk '{print $1}' | while read line
    do
        umount $line
	sleep 0.2
    done
}
#删除分区
function partTable_remove()
{
    fdisk -l |  grep -v Disk | grep -v Device| grep -v Units| grep -v Sector| grep -v size| grep -v size|grep sda|awk '{print $1}' | while read line
    do
	    echo "remove $line"
        echo "
	d


	w
	" | fdisk /dev/sda
	sleep 0.2
   done
}
function partTable_mkfs()
{
    ret=`fdisk -l |  grep -v Disk | grep -v Device| grep -v Units| grep -v Sector| grep -v size| grep -v size|grep sda|awk '{print $1}' | wc -l`
    if [ $ret -eq 2 ] ; then
        echo 'y
	'| mkfs.fat /dev/sda1
	sleep 0.2
        echo 'y
	'| mkfs.ext4 /dev/sda2 
    elif [ $ret -eq 1 ] ; then
        echo 'y
	'| mkfs.ext4 /dev/sda1
    fi
}
function partTable_create()
{
    size=$1
    echo "
    o
    w
    "|fdisk /dev/sda
    sleep 0.2
    if [ ! -z ${size} ] ; then
	    echo "create fatfs "${size}
        echo "
	n


	
	+${size}
	t
	b

	w
	" | fdisk /dev/sda
	sleep 0.2
    fi
    echo "
    n



    

    w
    " | fdisk /dev/sda
    sleep 0.2
    partTable_mkfs
}

parts_umount
partTable_remove
partTable_create $1


